package com.neca.auction.pages;

import java.awt.SystemColor;

import org.apache.tapestry.SelectModel;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.util.EnumSelectModel;

import com.neca.auction.dbb.DBBroker;
import com.neca.auction.model.Category;
import com.neca.auction.model.CurrentUser;
import com.neca.auction.model.Product;
import com.neca.auction.model.User;

public class AddProduct {
	@ApplicationState
	private CurrentUser currentUser;
	
	private Product product;
	@Inject
	private Messages messages;

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
	
	void onSubmitFromProductEditor(){
		System.out.println("The form was submitted!!!");
		
	}
	
	void onValidate(){
		
	}
	Object onSuccess(){
		DBBroker dbbroker=DBBroker.getDbbroker();
		User user=new User();
		user.setUserName(currentUser.getUserName());
		User user1=dbbroker.getUserByUserName(user);
		product.setUserID(user1.getUserID());
		
		dbbroker.addProduct(product);
		return MyProducts.class;
		
	}
	
	public SelectModel getCategories(){
		return new EnumSelectModel(Category.class, messages);
	}

}
